home *** CD-ROM | disk | FTP | other *** search
- #include <dos.h>
- #include <string.h>
- #include "drvrfunc.h"
-
- int SIMint; // Interrupt used to access SBSIM
-
- /*--- SBSIM error messages ------------------*/
- char *errorMsg[] = {NULL,
- "SBSIM currently in use",
- "Bad driver specified",
- "Bad function specified",
- "Voice process is already active",
- "Couldn't start CT-VOICE",
- "Couldn't start CTVDSK",
- "Invalid SBSIM handle",
- "Buffer not initialized yet",
- "Bad file name for load",
- "Bad file handle",
- "Driver not started yet",
- "XMS driver not installed",
- "No free SBSIM handles",
- "Bad file type specified",
- "Couldn't free XMS block",
- "Invalid source selected",
- "Get-Pan-Position failed",
- "Set-Pan-Position failed",
- "Set-Volume failed",
- "Couldn't start fade/pan",
- "Couldn't stop fade/pan",
- "Couldn't pause fade/pan",
- "Not a fade/pan operation",
- "Bad mode for fade/pan",
- "Couldn't start fade/pan",
- "Source not fading/panning",
- "FM or MIDI already playing",
- "Bad MIDI mapper format"};
-
- /*************************************************************************
- *
- * FUNCTION: FINDDVR - Searches for the requested driver's interrupt number
- * by looking for IDStr (in theis case it will be
- * SBSIM) in the interrupt vector table memory at the
- * offset (as in SEGMENT:OFFSET) location passed to
- * this function.
- *
- * Inputs: IDStr - driver ID string (i.e. "SBSIM").
- * IDOff - driver's ID offset.
- *
- * Output: interrupt number or 0 (error condition) if not found.
- *
- *************************************************************************/
- unsigned FindDvr(char *IDStr, unsigned int IDOff)
- {
- unsigned dvrInt,
- intFound = FALSE;
- char far *far *dvrVec;
-
- for(dvrInt = 0x80; (dvrInt < 0x0C0) && (intFound == FALSE); ++ dvrInt)
- {
- dvrVec = MK_FP(0, dvrInt * 4);
- if(!_fstrncmp((char far *)MK_FP(FP_SEG(*dvrVec), IDOff), IDStr,
- sizeof(IDStr)))
- {
- intFound = TRUE;
- }
- }
-
- if(intFound == TRUE)
- return(--dvrInt);
-
- return(0);
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETDVRINFO - Get status, entry point, buffer location, and
- * buffer size from SBSIM. The DVRINFO struct gets
- * loaded with this information
- *
- * Inputs: driver - driver to get info on.
- * *dvrInfo - pointer to DVRINFO structure.
- *
- * Output: status - the driver's status.
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- int GetDvrInfo(DRIVER driver, DVRINFO *dvrInfo)
- {
- int dvrLoc;
-
- dvrLoc = 1 << driver;
- if(GetDrvrs() & dvrLoc)
- {
- dvrInfo->status = LOADED;
- GetAddress(driver, &dvrInfo->entry);
- if(GetBufInfo(driver, &dvrInfo->bufLoc, &dvrInfo->bufSize) != SIMerr_NoErr)
- {
- dvrInfo->bufLoc = 0;
- dvrInfo->bufSize = 0;
- }
- }
- else
- dvrInfo->status = MISSING;
-
- return(dvrInfo->status);
- }
-
- /*************************************************************************
- *
- * FUNCTION: VERSION - Get the current version of SBSIM.
- *
- * Inputs: none
- *
- * Output: version = high byte, sub-version = low byte.
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- unsigned Version(void)
- {
- union REGS inregs,
- outregs;
-
- inregs.h.bh = 0; // control function
- inregs.h.bl = 0; // query version sub-fn
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax); // return version number
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETDRVRS - Determines which drivers are loaded.
- *
- * Inputs: none
- *
- * Output: bit field indicating which drivers are loaded.
- *
- * bit 0 - FM driver
- * bit 1 - Double disk buffered voice driver
- * bit 2 - Memory voice driver
- * bit 3 - Auxiliary driver (mixer)
- * bit 4 - MIDI driver
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- unsigned GetDrvrs(void)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = 0; // control function
- inregs.h.bl = 1; // query drivers sub-fn
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax); // return driver bit field
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETADDRESS - Returns selected driver's entry address.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 3 - Auxiliary driver (mixer)
- * 4 - MIDI driver
- * *address - storage for entry address pointer
- *
- * Output: 0 if no error.
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR GetAddress(DRIVER driver, long *address)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = 0; // control function
- inregs.h.bl = 2; // driver entry address sub-fn
- inregs.x.ax = driver;
- int86(SIMint, &inregs, &outregs);
- *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
- if(!outregs.x.cflag) // test for errors
- return(0); // return result
-
- return(outregs.x.ax); // error occured
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETBUFINFO - Returns selected driver's buffer address.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 4 - MIDI driver
- * *address - pointer to storage for buffer address pointer
- * *size - pointer storage for size of buffer (in Kbytes)
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR GetBufInfo(DRIVER driver, long *address, unsigned *size)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = 0; // control function
- inregs.h.bl = 5; // driver entry address sub-fn
- inregs.x.ax = driver;
- int86(SIMint, &inregs, &outregs);
- *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
- *size = outregs.x.cx; // return buffer size
- if(!outregs.x.cflag) // test for errors
- return(0); // No error
-
- return(outregs.x.ax); // error occured
- }
-
- /*************************************************************************
- *
- * FUNCTION: STARTSND - Initializes the driver for output.
- *
- * Inputs: driver: 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- * *ptr - pointer to filename or memory location.
- *
- * type: EXTENDED_MEM_VOD - Play a .VOC file from extended
- * memory. #defined in DVRVFUNC.H
- * NULL - Anything except a .VOC file from extended memory
- *
- * SBSIMHandle - value obtained by LoadExtMem() if using extended
- * memory; any value if not.
- *
- * Output: Initialization result
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR StartSnd(DRIVER driver, void far *ptr, char type, int SBSIMHandle)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 0; // start sound source function
- inregs.x.cx = 0;
- if (type == EXTENDED_MEM_VOC)
- {
- inregs.x.ax = SBSIMHandle;
- inregs.x.dx = 0;
- }
- else // NOT EXTENDED MEMORY .VOC FILE
- {
- inregs.x.ax = FP_OFF(ptr); // pointer to filename or data buffer
- inregs.x.dx = FP_SEG(ptr);
- }
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax); // return initialization result
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETSNDSTAT - Get the driver's status.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- *
- * Output: Current status
- *
- * note: requires SIMint be defined before calling.
- *
- * RETURNS: -1 (negative one) if still playing
- * 0 (zero) if done playing
- *
- *************************************************************************/
- unsigned GetSndStat(DRIVER driver)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 5; // get sound status function
- inregs.x.cx = 0;
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax); // return status
- }
-
- /*************************************************************************
- *
- * FUNCTION: PLAYSND - Plays music/voice on the selected driver.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- *
- * Output: Result
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR PlaySnd(DRIVER driver)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 1; // play sound function
- inregs.x.cx = 0;
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax); // return result
- }
-
- /*************************************************************************
- *
- * FUNCTION: STOPSND - Stops music/voice on the selected driver.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- *
- * Output: none
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- void StopSnd(DRIVER driver)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 2; // stop sound function
- inregs.x.cx = 0;
- int86(SIMint, &inregs, &outregs);
- }
-
- /*************************************************************************
- *
- * FUNCTION: PAUSESND - Pauses music/voice on the selected driver.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- *
- * Output: None
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- void PauseSnd(DRIVER driver)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 3; // pause sound function
- inregs.x.cx = 0;
- int86(SIMint, &inregs, &outregs);
- }
-
- /*************************************************************************
- *
- * FUNCTION: RESUMESND - Continues paused music/voice.
- *
- * Inputs: driver 0 - FM driver
- * 1 - Double disk buffered voice driver
- * 2 - Memory voice driver
- * 4 - MIDI driver
- *
- * Output: none
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- void ResumeSnd(DRIVER driver)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = driver + 1;
- inregs.h.bl = 4; // resume sound function
- inregs.x.cx = 0;
- int86(SIMint, &inregs, &outregs);
- }
-
- /*************************************************************************
- *
- * FUNCTION: GETVOLUME - Get the source's volume.
- *
- * Inputs: source 0 - Master volume
- * 1 - Voice volume
- * 2 - MIDI volume
- * 3 - CD volume
- * 4 - Line-in volume
- * 5 - Microphone volume
- * *volume - source's volume returned in this variable
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR GetVolume(SOURCE source, unsigned *volume)
- {
- union REGS inregs, outregs;
-
- inregs.x.ax = source;
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 0; // get source volume sub-function
- int86(SIMint, &inregs, &outregs);
- *volume = outregs.x.ax; // return volume
- if(outregs.x.cflag)
- return(outregs.x.ax); // return error code
- return(0);
- }
-
- /*************************************************************************
- *
- * FUNCTION: SETVOLUME - Set the source's volume.
- *
- * Inputs: source 0 - Master volume
- * 1 - Voice volume
- * 2 - FM volume
- * 3 - CD volume
- * 4 - Line-in volume
- * 5 - Microphone volume
- * volume - source's new volume
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *
- *************************************************************************/
- SIMERR SetVolume(SOURCE source, unsigned volume)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 1; // set source volume sub-function
- inregs.x.ax = source;
- inregs.x.dx = volume;
- int86(SIMint, &inregs, &outregs);
- return(outregs.x.ax);
- }
-
- /*************************************************************************
- * FUNCTION: GETGAIN - Get the SB16's gain.
- *
- * Inputs: direction 0 - Input
- * 1 - Output
- * *level - storage for the gain's level
- * MSB = left
- * LSB = right
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *************************************************************************/
- SIMERR GetGain(int direction, unsigned *level)
- {
- union REGS inregs, outregs;
-
- inregs.x.ax = direction;
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 2; // get gain sub-function
- int86(SIMint, &inregs, &outregs);
- *level = outregs.x.ax; // return gain's level
- if(outregs.x.cflag)
- return(outregs.x.ax); // return error code
- else
- return(0);
- }
-
- /*************************************************************************
- * FUNCTION: SETGAIN - Set the SB16's gain.
- *
- * Inputs: direction 0 - Input
- * 1 - Output
- * level - storage for the gain's level
- * MSB = left
- * LSB = right
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *************************************************************************/
- SIMERR SetGain(int direction, unsigned level)
- {
- union REGS inregs, outregs;
-
- inregs.x.ax = direction;
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 3; // set gain sub-function
- inregs.x.dx = level; // gain's level
- int86(SIMint, &inregs, &outregs);
- if(outregs.x.cflag)
- return(outregs.x.ax); // return error code
- else
- return(0);
- }
-
- /*************************************************************************
- * FUNCTION: GETTONE - Get the SB16's tone.
- *
- * Inputs: band 0 - Treble
- * 1 - Bass
- * *level - storage for the tone level
- * MSB = left
- * LSB = right
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *************************************************************************/
- SIMERR GetTone(int band, unsigned *level)
- {
- union REGS inregs, outregs;
-
- inregs.x.ax = band;
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 4; // get tone sub-function
- int86(SIMint, &inregs, &outregs);
- *level = outregs.x.ax; // return tone level
- if(outregs.x.cflag)
- return(outregs.x.ax); // return error code
- else
- return(0);
- }
-
- /*************************************************************************
- * FUNCTION: SETTONE - Set the SB16's tone.
- *
- * Inputs: band 0 - Treble
- * 1 - Base
- * level - storage for the gain's level
- * MSB = left
- * LSB = right
- *
- * Output: 0 if no error
- *
- * note: requires SIMint be defined before calling.
- *************************************************************************/
- SIMERR SetTone(int band, unsigned level)
- {
- union REGS inregs, outregs;
-
- inregs.x.ax = band;
- inregs.h.bh = 4; // auxilary function
- inregs.h.bl = 5; // set tone sub-function
- inregs.x.dx = level; // tone level
- int86(SIMint, &inregs, &outregs);
- if(outregs.x.cflag)
- return(outregs.x.ax); // return error code
- else
- return(0);
- }
-
- /*************************************************************************
- *
- *
- * FUNCTION: LoadExtMem() - Load a .VOC file into extended memory.
- *
- * DESCRIPTION: The parameter passed is far pointer to a null terminated
- * string that contains the filename to be loaded into
- * extended memory. (Example: C:\VOICE\TEST.VOC)
- *
- *
- *
- * RETURNS: If successful, the SBSIM handle to extended memory will be
- * returned. (This handle will be used by FreeExtMem() to free
- * the memory.) If not successful, an SIMERR type will be
- * returned.
- *
- *************************************************************************/
- SIMERR LoadExtMem(void far *Ptr)
- {
- union REGS inregs, outregs;
-
- inregs.x.dx = FP_OFF(Ptr);
- inregs.x.ax = FP_SEG(Ptr); // Load DS register via AX register
- asm {
- mov ds, ax
- }
-
- inregs.h.bh = 0;
- inregs.h.bl = 16;
- inregs.x.ax = 0;
- inregs.x.cx = 0; // Have driver assign you a handle (returned in AX)
- int86(SIMint, &inregs, &outregs);
-
- return(outregs.x.ax); // return extended mem. handle
- }
-
- /*************************************************************************
- *
- *
- * FUNCTION: FreeExtMem() - Releases the memory in extended memory.
- *
- * DESCRIPTION: Pass the SBSIMHandle obtained by LoadExtMem() to this
- * function. The extended memory used by the LoadExtMem()
- * will then be freed.
- *
- * RETURNS: 0 - (zero) if there are NO errors. Otherwise a SIMERR type
- * will be returned.
- *
- *************************************************************************/
- SIMERR FreeExtMem(int SBSIMHandle)
- {
- union REGS inregs, outregs;
-
- inregs.h.bh = 0;
- inregs.h.bl = 19;
- inregs.x.ax = SBSIMHandle;
- int86(SIMint, &inregs, &outregs);
-
- return(outregs.x.ax); // return result
- }
-